﻿Ext.require('Ext.*');
/////////////////////////////////////////////////////////////////////////model
  Ext.define('workflow.models.dict', {
  extend: 'Ext.data.Model',
  alias:'widget.dict',
  fields: [
  { type:'string', name: 'id' },
  { type:'string', name: 'type' },
  { type:'string', name: 'text' },
  { type:'string', name: 'Remark' },
  { type:'string', name: 'ParentID' },
  { type:'string', name: 'IsGroup' },
  { type:'int', name: 'orderID' }
  ]
  });

  Ext.define('mainmodel', {
  extend: 'Ext.data.Model',
  idProperty: 'id',
  fields: [
  { name: 'id',  type:'string'},
  { name: 'gdgs', type:'string' },
  {  name: 'yhjt',type:'string' },
  {  name: 'yhly',type:'string' },
  { type:'string', name: 'yhbh' },
  { type:'string', name: 'yhdwID' },
  { type:'string', name: 'yhdw' },
  { type:'string', name: 'yhzyfl' },
  { type:'string', name: 'yhfxr' },
  { type:'string', name: 'fxrdwID' },
  { type:'string', name: 'fxrdw' },
  { type:'date', name: 'fxrq',dataFormat:'Y/m/d' },
  { type:'string', name: 'fxyhnr' },
  { type:'string', name: 'knhg' },
  { type:'string', name: 'ypgdj' },
  { type:'string', name: 'ypgfzr' },
  { type:'string', name: 'ypgrq1' },
  { type:'string', name: 'ypgsh2' },
  { type:'string', name: 'ypgrq2' },
  { type:'string', name: 'ypgsh3' },
  { type:'string', name: 'ypgrq3' },
  { type:'string', name: 'pgdj' },
  { type:'string', name: 'pgfzr' },
  { type:'string', name: 'pgrq1' },
  { type:'string', name: 'pgsh2' },
  { type:'string', name: 'pgrq2' },
  { type:'string', name: 'pgsh3' },
  { type:'string', name: 'pgrq3' },
  { type:'string', name: 'pgsh4' },
  { type:'string', name: 'pgrq4' },
  { type:'string', name: 'ykcs' },
  { type:'string', name: 'zgcs' },
  { type:'string', name: 'zldw' },
  { type:'string', name: 'zlr' },
  { type:'string', name: 'zlrq1' },
  { type:'string', name: 'zlrq2' },
  { type:'string', name: 'zlwcqc' },
  { type:'string', name: 'yssqdw' },
  { type:'string', name: 'yssqfzr' },
  { type:'string', name: 'yssqrq' },
  { type:'string', name: 'yszzdw' },
  { type:'string', name: 'ysyj' },
  { type:'string', name: 'ysjl' },
  { type:'string', name: 'yssfxc' },
  { type:'string', name: 'yszz' },
  { type:'string', name: 'ysrq' },
  { type:'string', name: 'lcflag' },
  { type:'string', name: 'tjflag' },
  { type:'string', name: 'bhflag' }
  ]
  });
  
  Ext.define('workflow.models.treemodel', {
                                    extend: 'Ext.data.Model',
                                    fields: [{
                                    name: 'text',
                                    type:'string'
                                    }, {name:'id',type:'string'},{name: 'lead',type:'bool'}]
                                    
});

////////////////////////////////////////////////////////////////store
var taskStore=Ext.create('Ext.data.Store',{
                    model:'mainmodel',
                    autoLoad: true,
                    autoSync: true,
                    //pageSize:5,
                    //queryMode: 'local',
                    proxy: {
                        type: 'ajax',
                        //api: {
                        url: 'workflow_tasklist_ajax.aspx?action=read',
                        //},
                        reader: {
                            type: 'json',
                            successProperty: 'success',
                            root: 'data',
                            totalProperty:'total',
                            messageProperty: 'message'
                        },
                        extraParams: {
                            wfid: 100
                        },
                        listeners: {
                            exception: function(proxy, response, operation) {
                                Ext.MessageBox.show({
                                    title: 'REMOTE EXCEPTION',
                                    msg: operation.getError(),
                                    icon: Ext.MessageBox.ERROR,
                                    buttons: Ext.Msg.OK
                                });
                            }
                        }
                    }
                });

var yhlyStore=Ext.create('Ext.data.Store',{
                    model:'workflow.models.dict',
                    autoLoad: true,
                    queryMode: 'local',
                    proxy: {
                        type: 'ajax',
                        url: 'workflow_dict_ajax.aspx?action=read',
                        reader: {
                            type: 'json',
                            root: 'data'
                        }
                        },
                        extraParams: {
                            type: 'yhly'
                        }
                    
                });





///////////////////////////////////////////////////////////////////view
Ext.define('workflow.views.wftree', {
    extend: 'Ext.tree.Panel',
    alias:'widget.wftree',
    collapseDirection: 'left',
    collapsed: false,
    collapsible: true,
    title: '流程管理',
    rootVisible: true,
    root:{id:"000",text:'流程',expanded:true},
    store: Ext.create('Ext.data.TreeStore',{
	    model:'workflow.models.treemodel',
	    autoLoad: true,
        autoSync: true,
        queryMode: 'local',
        proxy: {
            type: 'ajax',
            api: {
            read: 'workflow_tree_ajax.aspx?action=read'
            },
            reader: {
                type: 'json',
                successProperty: 'success',
                root: 'data',
                messageProperty: 'message'
            },
            listeners: {
                exception: function(proxy, response, operation) {
                    Ext.MessageBox.show({
                        title: 'REMOTE EXCEPTION',
                        msg: operation.getError(),
                        icon: Ext.MessageBox.ERROR,
                        buttons: Ext.Msg.OK
                    });
                }
            }
        }
     
    }),//treestore,

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            viewConfig: {

            }
        });

        me.callParent(arguments);
    },
    listeners : {  
        afterrender: function (tree) {
              tree.getSelectionModel()
         },
        itemclick : function(view,re){  
            treeClick(re.data);
            //Ext.getCmp('com_source_1').setDisabled(false);
           
        },
        load: function(obj){
            this.getSelectionModel().select(1);
            treeClick(Ext.getCmp('wftree1').getRootNode().firstChild.data);
           //this.fireEvent('itemclick',Ext.getCmp('wftree1').getRootNode().firstChild);
        }
    }  
});

var treeClick=function(data)
{
    if(data.id=='100' || data.id=='101')
            {
                Ext.getCmp('mainform1').setTitle('隐患排查治理档案表--'+data.text);
                Ext.getCmp('mainform1').setVisible(true);
                Ext.getCmp('tasklist1').setVisible(false);
            }
            else{
                Ext.getCmp('tasklist1').setTitle('任务列表--'+data.text);
                Ext.getCmp('mainform1').setVisible(false);
                Ext.getCmp('tasklist1').setVisible(true);
            Ext.getCmp('tasklist1').store.load({
                 params: {
                              wfid: data.id
                         }
            }); 
             }
}; 


Ext.define('workflow.views.mainform', {
    extend: 'Ext.form.Panel',
    alias: 'widget.mainform',
    border: '',
    height: 1240,
    id: 'form_total',
    autoScroll: true,
    title: '隐患排查治理档案表',

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    xtype: 'panel',
                    height: 265,
                    id: 'discover',
                    layout: {
                        type: 'anchor'
                    },
                    collapsible: true,
                    title: '发现',
                    items: [
                        
                        {
                                    xtype: 'combobox',
                                    id: 'yhly@100@101',
                                    name: 'yhly',
                                    fieldLabel: '　隐患来源',
                                    labelWidth: 65,
                                    editable: false,
                                    displayField:'text',
                                    valueField:'text',
                                    columnWidth: 0.3,
                                    store:copy
                                }
                    ]
                }
            ]
        });

        me.callParent(arguments);
    },
   
    setActiveRecord: function(record) {
                    this.activeRecord = record;
                    if (record) {
                        this.getForm().loadRecord(record);
                    } else {
                        this.getForm().reset();
                    }
                },
    
    
});



Ext.define('workflow.views.tasklist', {
                extend: 'Ext.grid.Panel',
                alias: 'widget.tasklist',

                requires: [
        'Ext.grid.plugin.CellEditing',
        'Ext.form.field.Text',
        'Ext.toolbar.TextItem'
    ],
                title:'任务列表',
                initComponent: function() {

                    this.editing = Ext.create('Ext.grid.plugin.CellEditing');

                    Ext.apply(this, {
                        iconCls: 'icon-grid',
                        frame: true,
                        plugins: [this.editing],
                        dockedItems: [{
                                                    xtype: 'toolbar',
                                                    items: [{
                                                        iconCls: 'icon-exec',
                                                        text: '执行',
                                                        disabled: true,
                                                        itemId: 'exec',
                                                        scope: this,
                                                        handler: this.onExecClick
                                                    }]
                                                    }/*,
                                                    {
                                                        xtype: 'pagingtoolbar',
                                                        store: taskStore,  // same store GridPanel is using
                                                        dock: 'bottom', //分页 位置
                                                        emptyMsg: '没有数据',
                                                        displayInfo: true,
                                                        displayMsg: '当前显示{0}-{1}条记录 / 共{2}条记录 ',
                                                        beforePageText: '第',
                                                        afterPageText: '页/共{0}页'
                                                    }*/],
                                        columns: [{
                                            text: 'id',
                                            width: 40,
                                            sortable: true,
                                            hidden:true,
                                            dataIndex: 'id'
                                        }, {
                                            header: '隐患简题',
                                            width: 100,
                                            sortable: true,
                                            dataIndex: 'yhjt',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '隐患来源',
                                            width: 100,
                                            sortable: true,
                                            dataIndex: 'yhly',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '隐患编号',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yhbh',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '隐患单位',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yhdw',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '专业分类',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yhzyfl',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '发现人',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yhfxr',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '发现日期',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'fxrq',
                                            renderer:Ext.util.Format.dateRenderer,
                                            field: {
                                                type: 'datefield'
                                            }
                                        },  {
                                            header: '流程状态',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'lcflag',
                                            field: {
                                                type: 'textfield'
                                            }
                                        },{
                                            header: '预评估负责人',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'ypgfzr',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '评估负责人',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'pgfzr',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '治理人',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'zlr',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '是否消除',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yssfxc',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '验收组长',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'yszz',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }, {
                                            header: '验收日期',
                                            flex: 1,
                                            sortable: true,
                                            dataIndex: 'ysrq',
                                            field: {
                                                type: 'textfield'
                                            }
                                        }]
                                        });
                                        this.callParent();
                                        this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
                                    },
                                    onSelectChange: function(selModel, selections) {
                                        this.down('#exec').setDisabled(selections.length === 0);
                                    }
                                });
                                



/////////////////////////////////////////////////////////all
var main = Ext.create('Ext.window.Window', {
                                            width: 960,
                                            height:600,
                                            layout: {
                                                type: 'hbox',
                                                align: 'stretch'
                                            },
                                            items: [{
                                                xtype:'wftree',
                                                id:'wftree1',
                                                width:200,
                                                padding:'0 5 0 0'
                                                
                                            },{
                                                xtype:'mainform',
                                                title: '一般事故',
                                                id:'mainform1',
                                                itemId:'mainform1',
                                                width:750
                                            },{
                                                xtype:'tasklist',
                                                id:'tasklist1',
                                                
                                                width:1000,
                                                store:taskStore,
                                                onExecClick: function() {
                                                 //alert();
                                                        var selection = this.getView().getSelectionModel().getSelection()[0];
                                                       main.child('#mainform1').setActiveRecord(selection);// || null);
                                                        Ext.getCmp('mainform1').setVisible(true);
                                                        Ext.getCmp('tasklist1').setVisible(false);
                                                        //Ext.getCmp('com_source_@101').setRawValue('aaaa');
                                                    }
                                                  
                                            }]
                                            });

Ext.onReady(function(){
Ext.tip.QuickTipManager.init();
  
   dictStore.on('load',function(store){
       copy.filter('type','yhly');
   });
   main.show();
});